#===============================================
# Code written by Joe France (joeprogram.com)
# Released under code.google.com/p/video-scholar/
# with the MIT license (aka, the do-whatever-you-want-with-it license)
#===============================================

import pyglet
from pyglet.window import key
from pyglet.window import mouse
from pyglet.gl import *

from GUI import GUI
from Timeline import Timeline
from StartState import StartState
from MainState import MainState

class VideoScholar( object ):
	'''
	VideoNote is the application-level object
	VideoNote is a program for creating visual event timelines
	from a video.  It has two uses: to assist in creating visualizations
	of events that may be paired with emotions, and to track statistics
	about the number of times and frequency with which those events happen.
	
	So it should be able to answer questions like:
		How often do I ask a question in improv?
		How often am I being rewarded in this video game?
		Why is this video game so frustrating?
		
	Sounds courtesy of pdsounds.org
	'''
	
	WIDTH = 800
	HEIGHT = 481
	
	VERSION = 0.1
	
	def __init__( self ):

		self.window = pyglet.window.Window( width= self.WIDTH, height= self.HEIGHT, resizable=False )
		
		# For testing
		self.states = [ StartState( self ) ]
		#self.states = [MainState( self, r"C:\dev\video-scholar\fraps.avi")]
		
		# Set alpha blending on
		glEnable(GL_BLEND)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
		
		@self.window.event
		def on_draw():
			self.window.clear()
			self.states[-1].draw() # The last state in the list is the one that gets priority
						
		@self.window.event
		def on_key_press(symbol, modifiers):
			
			self.states[-1].key_press(symbol, modifiers)				
				
		# NOTE: Coordinates are given as integers
		#       With (0,0) being the bottom-right corner of the window
		@self.window.event
		def on_mouse_press( x, y, button, modifiers ):
			self.states[-1].mouse_press( x, y, button, modifiers )
			
		@self.window.event
		def on_mouse_motion( x, y, dx, dy ):
			self.states[-1].mouse_motion( x, y, dx, dy )			
			
		pyglet.app.run()
	
	def get_window( self ):
		return self.window
	
	
	def get_version( self ):
		return self.VERSION
	
	def push_state( self, state ):
		'''
		A method for states to add new states to the state stack
		'''
		self.states.append( state )
		
	def pop_state( self ):
		'''
		A method for states to remove themselves from the state stack
		'''
		self.states.pop()
	
# start the process
VideoScholar = VideoScholar()

